Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix relayStylePagination to better support existing and incoming without edges property #9201

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

alexstrat
Copy link

@alexstrat alexstrat commented Dec 15, 2021

This PR is suggested fix for #7944

The main problem comes from the fact the current implementation assumes that edges (and pageInfo) will always be present in non-null incoming and existing, and forces an empty edges array in cache. This PR debunks this assumption and add some tests of the expected behavior in these cases.

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@apollo-cla
Copy link

@alexstrat: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

…-7944-relay-style-pagination-add-empty-edges-array-while-we-dont-know
@alexstrat alexstrat changed the title Fix relayStylePagination for existing and incoming without edges properterty Fix relayStylePagination to better support existing and incoming without edges property Dec 15, 2021
Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into this @alexstrat! A couple initial questions below to steer your thinking.

If you run out of time to work on this, just let me know and I/we (the AC team) can take over.

Comment on lines 152 to 158
let merged: SafeReadonly<TExistingRelay<TNode, TConnectionExtraData>> = {
...(existing || {}),
...incoming,
}

if (!incoming.edges) {
return merged
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this correctly, the entire existing.pageInfo object will be replaced with incoming.pageInfo (not merged) whenever !incoming.edges?

I agree we should do something defensive in this case, but I don't think this version of merged is what we want to return.

Copy link
Author

@alexstrat alexstrat Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having !incoming.edges and incoming.pageInfo means that the query that produced this incoming does not select edges field but does select pageInfo, right?
Then, actually, I can't figure out a case where one would make a query that selects pageInfo and not edges, so I have some difficulty to come up with something logic.

What would you recommend doing?

src/utilities/policies/pagination.ts Outdated Show resolved Hide resolved
@alexstrat
Copy link
Author

alexstrat commented Jan 6, 2022

@benjamn thanks for reading and your questions! Sorry for the late response, I took some time off during the holidays! Please, continue your review, I'll be able to work on it.

@hwillson hwillson removed the 2022-01 label Jan 24, 2022
@alexstrat
Copy link
Author

@benjamn just a reminder that this PR is still apriori ready for a review - in opposite to the tag 🏓 awaiting-contributor-response seems to specify.

@benjamn benjamn removed the 🏓 awaiting-contributor-response requires input from a contributor label May 25, 2022
@anark
Copy link
Contributor

anark commented Mar 1, 2024

@benjamn , I'm also running into this. What is needed to get this looked at?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants